 
/* $Id: stampa.c 9 2009-12-29 12:25:52Z calicant $ */

#include "edilana.h"

extern struct Setup *conf;

void
StampaCol (
	char *nomefile,
	int lungmin,
	int tab[],
	int maxl,
	int resto,
	int cerca,
	char *stringa
){
int 	conta = 1, numlemmi = 0, l, numcol, lstr;
FILE 	*inlista;
char 	lemma[2*MAXSTRLEN], srest[MAXSTRLEN],
	stemp[MAXSTRLEN], linea[2*MAXSTRLEN] = "";


	if ((inlista = IOFile(nomefile,"r")) == NULL)
		return;

	maxl++;
	numcol = NUMCOLONNE/maxl;
	if ((numcol*maxl + 1) > NUMCOLONNE) numcol--;

	l = NUMCOLONNE - numcol*maxl - 1;
	if (l > numcol) maxl += l/numcol;

	if (cerca)  
		lstr = Stripnl(stringa);

	#ifdef AMIGA
	StampaFast(ON);
	#endif

	while (fgets(lemma,MAXSTRLEN,inlista) != NULL) {
		l = Stripnl(lemma);
		numlemmi++;
		if (l < lungmin) continue;
		if (cerca == 16) {
			if (strncmp(lemma, stringa, lstr)) continue;
		}
		else if (cerca)
			if (strstr(lemma, stringa) == NULL) continue;
		if (resto) {
			Sottraz(tab,lemma,srest,1,OFF);
			sprintf(stemp, "%s \x1b[%dm%-*s\x1b[0m",
				lemma,
				conf->coloresto,
				maxl-l-1,
				srest
			);
		}
		else sprintf(stemp,"%-*s",maxl,lemma);

		strcat(linea,stemp);

		if (!(conta++ % numcol)) {
			printf("%s\n",linea);
			linea[0] = '\0';
		}
		if (!((conta-1) % (numcol*NUMRIGHE))) {
			printf("\x1b[%dm_\x1b[0m\n",
			       conf->colorprompt);
		#ifdef AMIGA
			*lemma = tasto(lemma,0);
		#else
			*lemma = tasto();
		#endif	
			if (*lemma == 'q') goto esci;
		}
	}
	if (*linea != '\0') printf("%s\n",linea);
	if (lungmin != 1 || cerca) printf("%d/",conta-1);
	if (numlemmi > 10 || lungmin != 1 || cerca) printf("%d\n",numlemmi);
	printf("\n");

	esci:
		fclose(inlista);
		#ifdef AMIGA
		StampaFast(OFF);
		#endif

}

void
StampaVarProg (
	int  Resto,
	char *srest,
	int  Error,
	char *slast,
	int  Fissa,
	int  MinL,
	int  Candi,
	int  Nuove,
	int  ContaAnag[],
	int  Nomi
){

	#ifdef AMIGA
	StampaFast(ON);
	#endif

	printf( "Base:    %-40s [%d] [%d]\n"
		"Rest:    %-40s %s%s%s"
		"Sub:     %-40s %s%s\n"
		"Vocab:   %-40.40s [%d] [%d]\n"
		"Logfile: %-40.40s [%d/%d/%d] [%d/%d]\t%s\n"
	        "Cfgfile: %-40.40s %s%s\n\n",
		conf->nomecognome,
		Candi,
		Nomi,
		Resto == ON ? srest : "NO",
		conf->modor != OFF ? "AutoR" : "",
		conf->modor > AUTO_R ? "S" : "",
		conf->modor > AUTO_S ? "P\n" : "\n",
		slast,Fissa == ON ? "f " : "", Error != OFF ? "Error" : "",
		conf->vocabolario,Nuove,MinL,
		conf->logfile,ContaAnag[1],ContaAnag[0],
		ContaAnag[1]+ContaAnag[0]+ContaAnag[3],
		ContaAnag[4],ContaAnag[2]+ContaAnag[4],
		conf->datalog ? "d" : "",
	        conf->configflag ? conf->configfile : "NO",
		conf->promptora ? "h" : "",
	        conf->autocandy ? "c" : ""
);

	#ifdef AMIGA
	StampaFast(OFF);
	#endif

}
